package com.google.code.sms.android.parser;

import com.google.code.sms.android.domain.MediaElement;

import android.content.Context;

/**
 * @author Sindre Mehus
 */
public class MediaElementEntryParser extends AbstractParser {

    public MediaElementEntryParser(Context context) {
        super(context);
    }

    protected MediaElement.Entry parseEntry() {
        MediaElement.Entry entry = new MediaElement.Entry();
        entry.setId(get("id"));
        entry.setParent(get("parent"));
        entry.setName(get("name"));
        entry.setMediaType(get("mediaType"));
        entry.setCoverArt(get("coverArt"));

        if (!entry.isDirectory())
        {
            entry.setContentType(get("contentType"));
            entry.setSize(getLong("size"));
            entry.setDuration(getInteger("duration"));
            entry.setBitRate(getInteger("bitRate"));
            entry.setPath(get("path"));
        }
        
        if(entry.isAudio() || entry.isVideo())
        {
        	entry.setTitle(get("title"));
        	entry.setYear(getInteger("year"));
        }
        
        if(entry.isAudio())
        {
        	entry.setArtist(get("artist"));
        	entry.setAlbum(get("album"));
            entry.setTrack(getInteger("track"));
            entry.setGenre(get("genre"));
            entry.setComment(get("comment"));
        }
        return entry;
    }
}